﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_VirtualManager_VirtualManager : PowerCreator.LMS.Web.Base.BasePage
{
    VirtualDirectory opVirtual = new VirtualDirectory();

    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            InitPage();

            string search = GetSearch();
            BinderPager(search);
            BinderGV(search,1);
        }
    }
    protected override void InitPage()
    {
        lbl_VirtualManager_InfoTitle.Text = GetLanageValueByKey("lbl_VirtualManager_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_VirtualManager_Name.Text = GetLanageValueByKey("lbl_VirtualManager_Name", PowerCreator.LMS.Language.LanagetItemType.Page);

        btn_Search.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Add.Text = GetLanageValueByKey("btn_VirtualManager_Add", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }

    private string GetSearch()
    {
        string search = string.Format("VirIisName like '%{0}%'", txt_VirIisName.Text);
        return search;
    }

    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = opVirtual.QueryVirtualCount(search);
        AspNetPager1.PageSize = LMSPageSize;
    }

    private void BinderGV(string search,int pageIndex)
    {
        DataTable dt = opVirtual.QueryVirtual(search, LMSPageSize, pageIndex);
        rptVirtual.DataSource = dt;
        rptVirtual.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderGV(search,AspNetPager1.CurrentPageIndex);
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        string url = "AddVirtual.aspx";
        Script.RedirectURL(url);
    }


    protected void rptVirtual_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "leditor")
        {
            string url = "EditVirtual.aspx?VirtualID=" + e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }
        else if (e.CommandName == "ldel")
        {
            if (!IsLicensed("DelVirtual"))
            {
                Label lbl_msg = (Label)e.Item.FindControl("lbl_msg");
                lbl_msg.Text = GetLanageValueByKey("msg_ManagerNew_checkmsg", PowerCreator.LMS.Language.LanagetItemType.Page);
            }
            else
            {
                if (opVirtual.DelVirtual(int.Parse(e.CommandArgument.ToString())))
                {
                    string search = GetSearch();
                    BinderPager(search);
                    BinderGV(search, AspNetPager1.CurrentPageIndex);
                }
            }
        }
    }
}
